package com.defysoft.waukids.slide;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.defysoft.waukids.BaseActivity;
import com.defysoft.waukids.R;

public class Member_Notifications_A extends BaseActivity implements
		OnClickListener {
	String PK_Mem_Email;
	Toolbar toolbar;

	SharedPreferences notifications;
	SharedPreferences.Editor editor;
	String push[] = new String[5]; // 소리, 진동, 푸시, 공지, 현장학습
	ImageView imageViews[] = new ImageView[5];

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.member_notifications_a);
		PK_Mem_Email = getIntent().getStringExtra("PK_Mem_Email");
		notifications = getSharedPreferences("notifications", MODE_PRIVATE);
		editor = notifications.edit();
		setStartData();
		setStartToolbar();

	}

	@Override
	public void setStartData() {
		super.setStartData();
		toolbar = (Toolbar) findViewById(R.id.MEMBER_NOTIFICATIONS_TOOL);
		imageViews[0] = (ImageView) findViewById(R.id.MEMBER_NOTIFICATIONS_SOUND_TV); // 소리옵션
		imageViews[1] = (ImageView) findViewById(R.id.MEMBER_NOTIFICATIONS_VIBRATION_TV); // 진동옵션
		imageViews[2] = (ImageView) findViewById(R.id.MEMBER_NOTIFICATIONS_PUSH_TV); // 푸쉬옵션
		imageViews[3] = (ImageView) findViewById(R.id.MEMBER_NOTIFICATIONS_NOTICE_TV); // 공지옵션
		imageViews[4] = (ImageView) findViewById(R.id.MEMBER_NOTIFICATIONS_SPOT_TV); // 현장학습옵션
		for (int i = 0; i < imageViews.length; i++) {
			imageViews[i].setOnClickListener(this);
		}
		setnow(); // 알림설정 현재값으로.
	}

	private void setStartToolbar() {
		toolbar.setNavigationOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	private void setnow() { // 현재 알림값으로 초기화.
		push[0] = notifications.getString("push_sound", "0");
		push[1] = notifications.getString("push_vibration", "0");
		push[2] = notifications.getString("push_push", "0");
		push[3] = notifications.getString("push_notice", "0");
		push[4] = notifications.getString("push_spot", "0");
		for (int i = 0; i < imageViews.length; i++) {
			if (push[i].equals("0")) {
				imageViews[i].setBackgroundResource(R.drawable.switch_on);
			} else {
				imageViews[i].setBackgroundResource(R.drawable.switch_off);
			}
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.MEMBER_NOTIFICATIONS_SOUND_TV:
			if (push[0].equals("0")) {
				/*textView[0].setText("꺼짐");*/
				imageViews[0].setBackgroundResource(R.drawable.switch_off);
				editor.putString("push_sound", "1");
				editor.commit();
				push[0] = "1";

			} else {
				imageViews[0].setBackgroundResource(R.drawable.switch_on);
				editor.putString("push_sound", "0");
				editor.commit();
				push[0] = "0";
			}
			break;
		case R.id.MEMBER_NOTIFICATIONS_VIBRATION_TV:
			if (push[1].equals("0")) {
				
				imageViews[1].setBackgroundResource(R.drawable.switch_off);
				editor.putString("push_vibration", "1");
				editor.commit();
				push[1] = "1";
			} else {

				
				imageViews[1].setBackgroundResource(R.drawable.switch_on);
				editor.putString("push_vibration", "0");
				editor.commit();
				push[1] = "0";
			}
			break;
		case R.id.MEMBER_NOTIFICATIONS_PUSH_TV:
			if (push[2].equals("0")) {
				imageViews[2].setBackgroundResource(R.drawable.switch_off);
				editor.putString("push_push", "1");
				editor.commit();
				push[2] = "1";
			} else {
				imageViews[2].setBackgroundResource(R.drawable.switch_on);
				editor.putString("push_push", "0");
				editor.commit();
				push[2] = "0";
			}
			break;
		case R.id.MEMBER_NOTIFICATIONS_NOTICE_TV:
			if (push[3].equals("0")) {
				imageViews[3].setBackgroundResource(R.drawable.switch_off);
				editor.putString("push_notice", "1");
				editor.commit();
				push[3] = "1";
			} else {
				imageViews[3].setBackgroundResource(R.drawable.switch_on);
				editor.putString("push_notice", "0");
				editor.commit();
				push[3] = "0";
			}
			break;
		case R.id.MEMBER_NOTIFICATIONS_SPOT_TV:
			if (push[4].equals("0")) {
				imageViews[4].setBackgroundResource(R.drawable.switch_off);
				editor.putString("push_spot", "1");
				editor.commit();
				push[4] = "1";
			} else {
				imageViews[4].setBackgroundResource(R.drawable.switch_on);
				editor.putString("push_spot", "0");
				editor.commit();
				push[4] = "0";
			}
			break;
		}
	}

}
